Fk:loadTranslationTable {
  ["s15__zhiheng"] = "制衡",
  [":s15__zhiheng"] = "出牌阶段限一次，你可以弃置任意张牌并摸等量的牌。若你以此法弃置了所有的手牌且你是主帅，你多摸X张牌（X为己方阵亡角色数）。",

  ["#s15__zhiheng"] = "制衡：弃置任意张牌并摸等量的牌，若弃置了所有手牌且是主帅，多摸X张牌（X为己方阵亡角色数）",

  ["$s15__zhiheng1"] = "不急不躁，稳谋应对。",
  ["$s15__zhiheng2"] = "制衡互牵，大局可安。",
}

local s15__zhiheng = fk.CreateSkill {
  name = "s15__zhiheng",
}

s15__zhiheng:addEffect("active", {
  anim_type = "drawcard",
  min_card_num = 1,
  target_num = 0,
  prompt = "#s15__zhiheng",
  max_phase_use_time = 1,
  card_filter = function(self, player, to_select, selected)
    return not player:prohibitDiscard(to_select)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local hand = player:getCardIds("h")
    local all_discarded = #hand > 0
    for _, id in ipairs(hand) do
      if not table.contains(effect.cards, id) then
        all_discarded = false
        break
      end
    end

    room:throwCard(effect.cards, s15__zhiheng.name, player, player)

    if not player.dead then
      local draw_num = #effect.cards
      -- 调试信息
      print("=== s15__zhiheng Debug ===")
      print("Player seat:", player.seat)
      print("All discarded:", all_discarded)
      print("Is commander:", player.seat == 2 or player.seat == 5)
      print("Hand cards count:", #hand)
      print("Discarded cards count:", #effect.cards)

      if all_discarded and (player.seat == 2 or player.seat == 5) then
        -- 计算阵亡角色数
        local dead_count = #table.filter(room.players, function(p) return p.dead end)
        print("Dead count:", dead_count)
        print("Original draw num:", draw_num)
        draw_num = draw_num + dead_count
        print("Final draw num:", draw_num)
      else
        print("Conditions not met for extra draw")
      end
      print("========================")

      room:drawCards(player, draw_num, s15__zhiheng.name)
    end
  end
})

return s15__zhiheng
